$NG.AllReady(function (
    page,
    {
        useDataIndexChange,
        useValuesChange,
        useUpdateRows,
        useBeforeClick,
        useUpdateRow,
    }
) {
    // 编辑页面逻辑
    const mstform = $NG.getCmpApi("p_form_pc_suspend");
    console.log(mstform, "mstform");
    // const grid = $NG.getCmpApi("p_form_employ_apply_d");
    if (page.oType == "add") {
        var pc = mstform.getItem("phid_pc")
        console.log('123123');
        if (pc.getValue() > '0') {

            GetPCInfo(pc.getValue())
        }

    }

    useValuesChange(({ args, form }) => {
        // 获取各个字段的值，默认为0如果值为空
        const u_kc_wzcb = mstform.getItem("u_kc_wzcb").getValue() || 0;
        const u_yfsssf = mstform.getItem("u_yfsssf").getValue() || 0;
        const u_yfsfwf = mstform.getItem("u_yfsfwf").getValue() || 0;
        const u_wrzcb = mstform.getItem("u_wrzcb").getValue() || 0;
        const u_yfsfwygcf = mstform.getItem("u_yfsfwygcf").getValue() || 0;
        const u_yfschf = mstform.getItem("u_yfschf").getValue() || 0;    
        const u_yfscpf = mstform.getItem("u_yfscpf").getValue() || 0;
        const u_zbfwf = mstform.getItem("u_zbfwf").getValue() || 0;
        const u_yqrsrje = mstform.getItem("u_yqrsrje").getValue() || 0;
    
        // 计算累计成本和当前利润额
        const ljcb = u_kc_wzcb + u_yfsssf + u_yfsfwf + u_wrzcb + u_yfsfwygcf + u_yfschf + u_yfscpf + u_zbfwf;
        const dqmle = u_yqrsrje - ljcb;
    
        // 更新目标字段的值
        mstform.getItem("u_ljcb").setValue(ljcb);
        mstform.getItem("u_dqmle").setValue(dqmle);
        mstform.getItem("u_ykje").setValue(u_yqrsrje - ljcb);
    }, ["p_form_pc_suspend.u_wrzcb", "p_form_pc_suspend.u_kc_wzcb"]);

    // 项目名称变化时自动带入产品线、事业部
    useValuesChange(({ args }) => {
        console.log(args[0], "aaaa1111");
        const phid_pc = args[0].phid_pc.value;
        if (phid_pc) {
            console.log(phid_pc);

            GetPCInfo(phid_pc)
        }
        console.log("执行到这了");
        // const u_yhkje = mstform.getFieldValue("u_yhkje"); //获取值
        // const u_htxe = mstform.getFieldValue("u_htxe"); //获取值
        // const u_yqrsrje = mstform.getFieldValue("u_yqrsrje"); //获取值
        // const u_ljcb = mstform.getFieldValue("u_ljcb"); //获取值
        // console.log(u_yhkje);
        // console.log(u_htxe);
        // console.log(u_yqrsrje);
        // console.log(u_ljcb);
        // $NG.updateState((updater) => {
        //     updater.data.p_form_pc_suspend.setProps({
        //         u_hkwcl: u_yhkje / u_htxe * 100,
        //         u_srwcl: u_yqrsrje / u_htxe * 100,
        //         u_dqmle: u_htxe - u_ljcb

        //     });
        // });

    }, "p_form_pc_suspend.phid_pc");

    // 盈亏计算

    function GetPCInfo(pcvalue) {

        $NG.execServer("GetPcCntInfo", { phid_pc: pcvalue }, function (res) {
            const data = JSON.parse(res.data);
            console.log(data);
            const zz = data[0].extendObjects.zz;
            const zz_oname = data[0].extendObjects.oname;
            const pc_no = data[0].extendObjects.pc_no;
            const cpx = data[0].extendObjects.cpx;
            const cpx_name = data[0].extendObjects.cpx_name;
            const xmjl = data[0].extendObjects.xmjl;
            const xmjl_name = data[0].extendObjects.xmjl_name;
            const qyzx = data[0].extendObjects.qyzx;
            const qyzx_name = data[0].extendObjects.qyzx_name;
            const htxe = data[0].extendObjects.htxe;
            const cntid = data[0].extendObjects.cntid;
            const cnt_name = data[0].extendObjects.cnt_name;
            const cnt_no = data[0].extendObjects.cnt_no;
            const xsry = data[0].extendObjects.xsry;
            const xsry_name = data[0].extendObjects.xsry_name;
            const zbrq = data[0].extendObjects.zbrq;
            const kgrq = data[0].extendObjects.kgrq;
            const wgrq = data[0].extendObjects.wgrq;
            const ht_taxrate = data[0].extendObjects.ht_taxrate;
            //  const qdmllb = data[0].extendObjects.qdmllb;

            $NG.updateState((updater) => {
                updater.data.p_form_pc_suspend.setProps({
                    u_division: { value: zz, label: zz_oname },
                    u_product_line: { value: cpx, label: cpx_name },
                    u_xmjl: { value: xmjl, label: xmjl_name },
                    u_region_center: { value: qyzx, label: qyzx_name },
                    u_pc_no: pc_no,
                    u_ht_name: { value: cntid, label: cnt_name },
                    u_ht_no: cnt_no,
                    u_xsry: { value: xsry, label: xsry_name },
                    u_htxe: htxe * (1 - ht_taxrate),
                    u_zb_dt: zbrq,
                    u_kg_dt: kgrq,
                    u_wg_dt: wgrq,
                    //       u_qdmll: qdmllb,

                });
            });
        });

        $NG.execServer("getPcZjInfo", { pc: pcvalue }, function (res) {
            const data = JSON.parse(res.data);
            console.log(data);
            const ljrkje = data[0].extendObjects.ljrkje;
            const ljjsje = data[0].extendObjects.ljjsje;
            const ljhkje = data[0].extendObjects.ljhkje;
            const srbyje = data[0].extendObjects.srbyje;
            const zbfwf = data[0].extendObjects.zbfwf;
            const ljkpje = data[0].extendObjects.ljkpje;
            const zzcpje = data[0].extendObjects.zzcpje;

            const u_kc_wzcb = mstform.getItem("u_yqrsrje").getValue(); //获取值
            const u_yfsssf = mstform.getItem("u_yfsssf").getValue(); //获取值
            const u_yfsfwf = mstform.getItem("u_yfsfwf").getValue(); //获取值
            const u_wrzcb = mstform.getItem("u_wrzcb").getValue(); //获取值

            $NG.updateState((updater) => {
                updater.data.p_form_pc_suspend.setProps({
                    u_yfschf: ljrkje,
                    u_yfsfwygcf: ljjsje,
                    u_yhkje: ljhkje,
                    u_yqrsrje: srbyje,
                    u_zbfwf: zbfwf,
                    u_ykpje: ljkpje,
                    u_yfscpf: zzcpje,
                    u_yqrsrje: ljrkje + srbyje,
                    u_ljcb: ljjsje + ljjsje + zbfwf + zzcpje + u_kc_wzcb + u_yfsssf + u_yfsfwf + u_wrzcb,
                    u_ykje: srbyje - (ljjsje + ljjsje + zbfwf + zzcpje + u_kc_wzcb + u_yfsssf + u_yfsfwf + u_wrzcb) 

                });
            });
        });



        $NG.execServer("SusGetSbqd", { pc: pcvalue }, function (res) {
            const data = JSON.parse(res.data);
            console.log(data);
            const qdmll = data[0].extendObjects.qdmll;
            const u_win_bid_svc_amt = data[0].extendObjects.u_win_bid_svc_amt;

            $NG.updateState((updater) => {
                updater.data.p_form_pc_suspend.setProps({
                    u_qdmll: qdmll,
                    u_zbfwf: u_win_bid_svc_amt,


                });
            });
        });

        $NG.execServer("GetSgJdInfo", { pc: pcvalue }, function (res) {
            const data = JSON.parse(res.data);
            console.log(data);
            const htxe = data[0].extendObjects.htxe;
            const ljcz = data[0].extendObjects.ljcz;
            const taxrate = data[0].extendObjects.taxrate;

            $NG.updateState((updater) => {
                updater.data.p_form_pc_suspend.setProps({
                    u_ztsgjd: ljcz / (htxe * (1 - taxrate)),

                });
            });
        });


        setTimeout(function () {
            console.log("执行到这了");
            const u_yhkje = mstform.getItem("u_yhkje").getValue(); //获取值
            const u_htxe = mstform.getItem("u_htxe").getValue(); //获取值
            const u_yqrsrje = mstform.getItem("u_yqrsrje").getValue(); //获取值

            const u_ljcb = mstform.getItem("u_ljcb").getValue(); //获取值
            console.log(u_yhkje);
            console.log(u_htxe);
            console.log(u_yqrsrje);
            console.log(u_ljcb);
            $NG.updateState((updater) => {
                updater.data.p_form_pc_suspend.setProps({
                    u_hkwcl: u_yhkje / u_htxe,
                    u_srwcl: u_yqrsrje / u_htxe,
                    u_dqmle: u_htxe - u_ljcb

                });
            });



        }, 2000)
    }

});





